function promiseAll(promise) {
    return new Promise((resolve,reject) => {
        if(!Array.isArray(promise)) {
            throw new Error('must be array')
        }
        var resolveCount = 0;
        var promiseNum = promise.length;
        var resolvedResult = [];
        for(let i = 0; i < promiseNum;i++) {
            // 启动并发
            Promise.resolve(promise[i])
                .then(value => {
                    resolveCount++;
                    resolvedResult[i] = value;
                    if(resolveCount == promiseNum) {
                        return resolve(resolvedResult)
                    }
                },err => {
                    return reject(err)
                })
        }
    })
}
// 测试用例
let p1 = new Promise(function(resolve,reject) {
    setTimeout(() => {
        resolve(1)
    },1000)
})
let p2 = new Promise(function(resolve,reject) {
    setTimeout(() => {
        resolve(2)
    },2000)
})
let p3 = new Promise(function(resolve,reject) {
    setTimeout(() => {
        resolve(3)
    },3000)
})
promiseAll([p1,p2,p3])
    .then(res => {
        console.log(res)
    })
    .catch(err => {
        console.log(err)
    })